package com.ctshk.rpc.insurance.util;

import com.ctshk.rpc.insurance.enums.CertificateTypeCode;

import java.util.Objects;

/**
 * 太平保险工具类
 */
public class PacificUtil {

    /**
     * 太平洋账号
     **/
    //仲介人代碼
    public static final String INTERMEDIARYCODE = "111800020000";  // test:020100210000
    //協議號
    public static final String AGREEMENTNO = "110000000018000002"; // test:010000000000000001
    //分配方案號
    public static final String SOLUTIONCODE = "1100000000180000020001"; // test:0100000000000000010000
    //登陆B2B出单系统的用户名
    public static final String OPERATORCODE = "0120114001"; // test:0100000001


    //年龄范围
    public static final int CHILD_AGE = 17;
    public static final int ADULT_AGE = 75;

    public static final int AGE_MIN_1146 = 18; // 1146险种特有年龄范围
    public static final int AGE_MAX_1146 = 65; // 1146险种特有年龄范围
    public static final String ADULT_CODE_1146 = "39";
    public static final String OLDMAN_CODE_1146 = "40";

    //太平保险年龄段Code
    public static final String CHILD_CODE = "28";
    public static final String ADULT_CODE = "29";
    public static final String OLDMAN_CODE = "30";

    /**
     * 获取证件类型
     */
    public static String getIdentifyType(Long certificateTypeId) {
        if (certificateTypeId == null) {
            return null;
        }
        if (Objects.equals(certificateTypeId, CertificateTypeCode.IDENTIFY_HK.getCode())) {
            return CertificateTypeCode.IDENTIFY_HK.getMsg();
        } else if (Objects.equals(certificateTypeId, CertificateTypeCode.PASSPORT.getCode())) {
            return CertificateTypeCode.PASSPORT.getMsg();
        } else if (Objects.equals(certificateTypeId, CertificateTypeCode.RETURN_HOME.getCode())) {
            return CertificateTypeCode.RETURN_HOME.getMsg();
        }
        return null;
    }

    /**
     * 获取年龄类型
     */
    public static String getAgeType(Integer age, String apiCode) {
        if (apiCode.equals("1146")) { // 特有险种1146
            if (age > AGE_MAX_1146) {
                return OLDMAN_CODE_1146;
            } else if (age >= AGE_MIN_1146) {
                return ADULT_CODE_1146;
            } else {
                return null;
            }
        } else { // 普通保险
            if (age == null) {
                return null;
            }
            if (age <= CHILD_AGE) {
                return CHILD_CODE;
            } else {
                if (age <= ADULT_AGE) {
                    return ADULT_CODE;
                } else {
                    return OLDMAN_CODE;
                }
            }
        }
    }

}
